<template>
    <div>
        <el-form   :model="model" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
            <el-form-item label="设备状态" prop="StatusName">
                <el-input v-model="model.StatusName"></el-input>
            </el-form-item>        
            <el-form-item label="备注" prop="Remark">
                <el-input v-model="model.Remark"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="submitForm">{{ isUpdate?'立即保存':'立即创建' }}</el-button>
                <el-button @click="resetForm">重置</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
export default {
    props: {
        model: {
            require: true,
            type: Object
        },
        isUpdate: {
            require: true,
            type: Boolean
        }
    },
    data() {
        return {
            UnitMeasureList:[],
            rules: {
                StatusName: { required: true, message: '请输入设备状态 ', trigger: 'blur' },
            }
        }
    },
    created(){
        this.getUnitMeasureAll();
    },  
    methods:{
        submitForm() {
            this.$refs['ruleForm'].validate((valid) => {
                if (valid) {

                    if(this.isUpdate){
                        this.put();
                    }
                    else{
                        this.add();
                    }

                } else {
                    this.showNotify('请输入必填项');
                    return false;
                }
            });
      },
      resetForm() {
        this.$refs['ruleForm'].resetFields();
      },
      add(){
        this.$http.postForm('/api/MachineryStatus',{model:this.model},{loading:this.$loading()})
        .then(res=>{
            this.$emit('callback');
        })

      },
      put(){
        this.$http.putForm('/api/MachineryStatus',{model:this.model},{loading:this.$loading()})
		.then((res)=>{
            this.$emit('callback');
		})
      },

      getUnitMeasureAll(){
        this.$http.get('/api/MachineryStatus/GetAll')
        .then(res=>{
            this.UnitMeasureList=res.Data ;
        })
      }
    }
}
</script>

<style></style>